<!DOCTYPE html>
<html>
    <head>
        <title>Pick-up Game</title>
        <link rel="stylesheet" href="style.css" type="text/css" />
        <script type="text/javascript" src="index.js"></script>
    </head>

    <body>

        <?php
        include_once('menu.php');

        // connect to database
        $conn_str = 'host=dbsrv1.cdf.toronto.edu dbname=csc309g23 user=csc309g23 password=ipheid5h';
        $conn = pg_connect($conn_str);

        // query database
        $query = 'SELECT * FROM sports  ORDER BY sport ASC';
        $result = pg_query($conn, $query);
        ?>

        <div class="container">
        <?php if (!empty($_SESSION['username'])) : ?>
          
          
          <h2>Sports</h2>
          <hr></hr>
                <form action="saveGlobal.php" method="post">
                    <input type="input" name="sport" />
                    <input type="submit" value="add sport" />
                    <input type="hidden" name="func" value="addSport" />
                </form>
                
                <form action="saveGlobal.php" method="post">
                    <select name="sport">
                        <?php while ($row = pg_fetch_row($result)) { ?>
                            <option><?= $row[0] ?></option>
                        <?php } ?>
                    </select>
                    <input type="submit" value="remove" />
                    <input type="hidden" name="func" value="removeSport" />
                </form>
                

            <?php
            // query database
            $query = 'SELECT * FROM countries ORDER BY country ASC';
            $result = pg_query($conn, $query);
            ?>

          <h2>Countries</h2>
          <hr></hr>
                <form action="saveGlobal.php" method="post">
                    <input type="input" name="country" />
                    <input type="submit" value="add country" />
                    <input type="hidden" name="func" value="addCountry" />
                </form>
                
                <form action="saveGlobal.php" method="post">
                    <select name="sport">
                        <?php while ($row = pg_fetch_row($result)) { ?>
                            <option><?= $row[0] ?></option>
                        <?php } ?>
                    </select>
                    <input type="submit" value="remove" />
                    <input type="hidden" name="func" value="removeCountry" />
                </form>
        <?php
        else :
            header('Location: /');
        endif;
        ?>
    </div>
    </body>

</html>
